// pages/add/add.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activePhone:'',
    customerPhone:'',
    company:'',
    remarks:'',
    status:[
      {text:"一般客户",value:0},
      {text:"意向客户",value:1},
      {text:"无意向客户",value:2},
      {text:"成交客户",value:3},
      {text:"黑名单",value:4}
    ],
    currentStatus:0
  },

   //手机号输入框失焦时
   phoneAdd(e){
    var $this = this
    $this.setData({
     activePhone:e.detail.value
    })
    console.log($this.data.activePhone)
  },
  //姓名输入框失焦时
  nameAdd(e){
    var $this = this
    $this.setData({
     customerPhone:e.detail.value
    })
    console.log($this.data.customerPhone)
  },
  //公司名字输入框失焦时
  companyAdd(e){
      var $this = this
      $this.setData({
        company:e.detail.value
      })
      console.log($this.data.company)
    },
  //备注信息输入框失焦时
  remarksAdd(e){
    var $this = this
    $this.setData({
      remarks:e.detail.value
    })
    console.log($this.data.remarks)
  },
    //状态选中
    complete(value){
      var $this =this
      $this.setData({
        currentStatus:value.detail
      })
    },
     //点击确认修改
  confirmAdd(){
    var userId = wx.getStorageSync('id')
    wx.showModal({
      title: '提示',
      content: '是否确认添加！',
      success :(res) => {
        if (res.confirm) {
    var token = wx.getStorageSync('TOKEN')
    wx.request({
      url: 'http://123.60.30.116:9999/app/phone/add', //仅为示例，并非真实的接口地址
      method:"POST",
      data: {
        activePhone:this.data.activePhone,
        customerPhone:this.data.customerPhone,
        company:this.data.company,
        remarks:this.data.remarks,
        status:this.data.currentStatus,
        userId:userId,
      },
      header: {
        'content-type': 'application/json',// 默认值
        'X-Access-Token':token
      },
      success(res){
        wx.showToast({ 
          title: res.data.message, 
          icon: 'success', 
          duration: 1000 
          })
        wx.switchTab({
          url: '/pages/customer/customer',
        })
      },
      fail(){
        wx.showToast({ 
          title: '接口调用错误！', 
          icon: 'fail', 
          duration: 1000 
          })
      }
    })
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})